/*
 * 
 */
package util;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Vector ;

/**
* This class  is an OutputStream Implementation letting to write in a String.
* 
* @author ter-topcased-ups
* @version 0.01, 2008/07/03
* @see 
*/
public class StringOutputStream extends OutputStream {

	private Vector<Byte> content ;
	
	public StringOutputStream () {
		content = new Vector<Byte>(512,512) ;
	}
		
	@Override
	public void write(int b) throws IOException {
		content.add((byte)b) ;
	}
	
	/**
	 * return, as a byte[], datas written on the stream since its
	 * creation.
	 */
	public byte[] getContent() {
		Byte[] forceType = new Byte[2] ;
		Byte[] refBytes = content.toArray(forceType);
		byte[] result = new byte[refBytes.length] ;
		for(int i = 0 ; i<refBytes.length ; i++) {
			result[i] = refBytes[i].byteValue() ;
		}
		return result;
	}
	
	/**
	 * return the content of the stream.
	 */
	public String toString() {
		return new String(getContent()) ;
	}

}
